// function *gen() {
//   let a = yield 1
//   console.log(a)
//   let b = yield 2
//   console.log(b)
//   let c = yield 3
//   console.log(c)
// }

// // let it = gen(123)
// let it = gen()
// it.next() // 第一次调用next函数时传递的参数 是无效的
// // 第二次next执行时传递的参数会返回给第一次yield的返回值
// it.next('hell0')

// next返回的是promise

let fs = require('fs')
// bluebird.js - 让所有浏览器都支持 ES6 Promise 对象
let bluebird = require('bluebird')
// 返回的回调用promise包裹
let read = bluebird.promisify(fs.readFile)

function *r() {
  let age = yield read('01.第一章.异步流程控制/4.generator/name.txt', 'utf8')
  let address = yield read(age, 'utf8')
  let r = yield read(address, 'utf8')
  return r
}

// let co = require('co')
// 实现co库
function co(it) {
  return new Promise(function(reslove, reject){
    function next(){

    }
  })
}
co(r()).then(data => {
  console.log('----------------')
  console.log(data)
})

/*
let it = r()
let {value, done} = it.next()
// console.log(value)  promise
// console.log(done)
// 这样子写很恶心
value.then(data => {
  console.log(data)
  let {value, done} = it.next(data)
  value.then(data => {
    console.log(data)
    let {value, done} = it.next(data)
    value.then(data => {
      console.log(data)
    })
  })
})
*/